package com.zcc.lesson04.utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.zcc.lesson02.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class C3P0Utils {
    static ComboPooledDataSource dataSource;
    static {
        try {
            //通过Factory创建DataSource对象
            dataSource = new ComboPooledDataSource();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    //获取连接
    //通过DataSource对象的getConnection方法
    //用return获得返回值
    public static Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }
    //释放连接
    public static void release(Connection connection, Statement statement, ResultSet resultSet) {
        JDBCUtils.release(connection, statement, resultSet);
    }
}
